{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "42fa8a82",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fa895f06",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'dict'> {'reqType': 0, 'perception': {'inputText': {'text': '火龙果用英文怎么说'}}, 'userInfo': {'apiKey': 'd5d5bb66f66d4da8bedb378df7adfa70', 'userId': '000001'}}\n",
      "<class 'str'> {\"reqType\": 0, \"perception\": {\"inputText\": {\"text\": \"\\u706b\\u9f99\\u679c\\u7528\\u82f1\\u6587\\u600e\\u4e48\\u8bf4\"}}, \"userInfo\": {\"apiKey\": \"d5d5bb66f66d4da8bedb378df7adfa70\", \"userId\": \"000001\"}}\n"
     ]
    }
   ],
   "source": [
    "TL_url = 'http://openapi.turingapi.com/openapi/api/v2'\n",
    "\n",
    "params = {\n",
    "    \"reqType\":0,\n",
    "    \"perception\": {\n",
    "        \"inputText\": {\n",
    "            \"text\": \"火龙果用英文怎么说\"\n",
    "        },\n",
    "    },\n",
    "    \"userInfo\": {\n",
    "        \"apiKey\": \"d5d5bb66f66d4da8bedb378df7adfa70\",\n",
    "        \"userId\": \"000001\"\n",
    "    }\n",
    "}\n",
    "\n",
    "print(type(params),params)\n",
    "print(type(json.dumps(params)),json.dumps(params))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "acee6c03",
   "metadata": {},
   "outputs": [],
   "source": [
    "res = requests.post(TL_url,data = json.dumps(params))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "f1fde7c0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Response [200]>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ce0fd068",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'pitaya'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res.json()['results'][0]['values']['text']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "9b29edcf",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'tuling'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-11-50118ff5bbcd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mtuling\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mTuLing\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mTuLing\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mTL_key\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'你好'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'tuling'"
     ]
    }
   ],
   "source": [
    "from tuling import TuLing\n",
    "TuLing(TL_key,'你好')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58e285ed",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
